//
//  YDProgressHUD.m
//  FreshMember
//
//  Created by qyc on 2019/4/19.
//  Copyright © 2019年 qyc. All rights reserved.
//

#import "CustomProgressHUD.h"

@implementation CustomProgressHUD

+ (instancetype)sharedHUD {
    static CustomProgressHUD *hud;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        hud = [[CustomProgressHUD alloc] initWithView:mainWindow];
    });
    return hud;
}

/**
 显示提示内容弹框
 
 @param text 提示内容
 @param time 消失时间，默认为2s
 */
+ (void)showMessage:(NSString *)text time:(NSTimeInterval)time {
    
    CustomProgressHUD *hud = [CustomProgressHUD sharedHUD];
    [hud show:YES];
    [hud setLabelText:text];
    [hud setMinSize:CGSizeZero];
    [hud setMode:MBProgressHUDModeText];
    [hud setRemoveFromSuperViewOnHide:YES];
    [hud setLabelFont:[UIFont boldSystemFontOfSize:TEXT_SIZE]];
    [[UIApplication sharedApplication].keyWindow addSubview:hud];
    
    if (time == 0) {
        time = 0.8f;
    }
    [hud hide:YES afterDelay:time];
}

/** 手动消失 */
+ (void)hide {
    [[CustomProgressHUD sharedHUD] hide:YES];
}

@end
